package game.ui.controls
{
	import engine.asset.*;
	import game.ui.core.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	
	public class RxBitmap extends RxUIElement implements RxIDataRenderer
	{
		protected var m_url:String;
		protected var m_bitmapData:BitmapData;
		protected var m_clipRect:Rectangle;
		protected var m_loaded:Boolean = false;
		protected var m_scaleMode:int = 0;
		protected var m_dataIndex:int;
		protected var m_data:Object;
		protected var m_selected:Boolean;
		protected var m_flipVertical:Boolean;
		protected var m_flipHorizontal:Boolean;
		private var m_suppressEvents:Boolean;
		private var m_trackingMouse:Boolean;
		private var mousePoint:Point;
		public var hit:Boolean = false;
		public static const SCALE_MODE_RESIZE:int = 0;
		public static const SCALE_MODE_REPEAT:int = 1;
		public static const SCALE_MODE_CENTER:int = 2;
		public static const SCALE_MODE_NONE:int = 3;
		
		public function RxBitmap(param1:String = null)
		{
			mouseEnabled = false;
			mouseChildren = false;
			if (param1)
			{
				this.url = param1;
			}
		}
		
		public function get url() : String
		{
			return this.m_url;
		}
		
		public function set url(param1:String) : void
		{
			this.SetUrl(param1, RxAsset.SOURCE_LOCAL);
			InvalidateSize();
		}
		
		public function SetUrl(param1:String, param2:int) : void
		{
			if (param1 != null && param1 != "")
			{
				if (this.m_url != param1)
				{
					this.m_bitmapData = null;
					this.m_url = param1;
					this.LoadURL(param2);
				}
			}
			else
			{
				this.m_bitmapData = null;
				this.m_url = null;
				graphics.clear();
				this.DispatchComplete();
			}
			InvalidateSize();
		}
		
		private function LoadURL(param1:int) : void
		{
			var _loc_2:RxAssetImage = null;
			this.m_loaded = false;
			graphics.clear();
			if (this.m_url)
			{
				_loc_2 = RxAssetImage.Create(this.m_url, null);
				_loc_2.SetSource(param1);
				_loc_2.AddCallback(new RxAssetCallback(this.OnImageLoaded));
				_loc_2.Load();
			}
		}
		
		protected function OnImageLoaded(param1:RxAssetCallback) : void
		{
			var _loc_2:RxAssetImage = null;
			if (param1.m_result)
			{
				_loc_2 = param1.m_asset as RxAssetImage;
				if (_loc_2.GetURL() == this.m_url)
				{
					this.m_bitmapData = _loc_2.GetBitmapData();
					InvalidateSize();
					this.m_loaded = true;
					this.DispatchComplete();
				}
			}
		}
		
		private function DispatchComplete() : void
		{
			if (hasEventListener(Event.COMPLETE))
			{
				dispatchEvent(new Event(Event.COMPLETE));
			}
		}
		
		public function GetData() : Object
		{
			return this.m_data;
		}
		
		public function GetDataIndex() : int
		{
			return this.m_dataIndex;
		}
		
		public function IsSelected() : Boolean
		{
			return this.m_selected;
		}
		
		public function SetData(param1:Object) : void
		{
			this.m_data = param1;
			if (this.m_data)
			{
				if (this.m_data is String)
				{
					this.url = this.m_data as String;
				}
				else if (this.m_data is Object)
				{
					if (this.m_data.hasOwnProperty("url"))
					{
						this.url = this.m_data.url;
					}
				}
			}
			else
			{
				this.url = null;
			}
		}
		
		public function SetDataIndex(param1:int) : void
		{
			this.m_dataIndex = param1;
		}
		
		public function SetSelected(param1:Boolean) : void
		{
			this.m_selected = param1;
			if (!this.m_data)
			{
				return;
			}
			if (!(this.m_data is String))
			{
				if (this.m_selected && this.m_data.hasOwnProperty("selectedUrl"))
				{
					this.url = this.m_data.selectedUrl;
				}
				else if (this.m_data.hasOwnProperty("url"))
				{
					this.url = this.m_data.url;
				}
			}
		}
	}
}